package cn.com.note.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.com.note.R;

/**
 * Created by SunFuLin on 2019/2/22.
 */

public class FragmentSignalTest extends Fragment {
    private Context context;
    private static FragmentSignalTest signalTest;
    private static String tagStr;
    public static FragmentSignalTest newInstance(String tag){
        tagStr=tag;
        if(signalTest==null){
            signalTest=new FragmentSignalTest();
        }
        return signalTest;
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.context=getContext();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_signalt,container,false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        RecyclerView rv1=view.findViewById(R.id.rv1);
        RecyclerView rv2=view.findViewById(R.id.rv2);
        List<String> data=new ArrayList<>();
        List<String> data2=new ArrayList<>();
        for (int i = 0; i <15 ; i++) {
            data.add("测试数据"+" "+i);
            data2.add("测试DA数据"+" "+i);
        }
        initData(rv1,data );
        initData(rv2,data2);
    }

    private void initData(RecyclerView rv1, List<String> data) {
        LinearLayoutManager lm=new LinearLayoutManager(getContext());
        lm.setOrientation(LinearLayoutManager.VERTICAL);
        rv1.setLayoutManager(lm);
        HomeAdapter adapter=new HomeAdapter(data,getContext());
        rv1.setAdapter(adapter);

    }

    class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder>
    {
        private List<String> mDatas;
        private Context mContext;
        public HomeAdapter(List<String> data,Context context) {
            mContext = context;
            mDatas = data;
        }
        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                    mContext).inflate(R.layout.item_select, parent,
                    false));
            return holder;
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position)
        {
            holder.tv.setText(mDatas.get(position));
        }

        @Override
        public int getItemCount()
        {
            return mDatas.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder
        {

            TextView tv;

            public MyViewHolder(View view)
            {
                super(view);
                tv = (TextView) view.findViewById(R.id.tv);
            }
        }
    }
}
